import {Component, OnInit} from '@angular/core';
import {_HttpClient} from '@delon/theme';
import {JpushService} from '../jpush.service';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {Jpush} from '../jpush';
import {NzMessageService} from 'ng-zorro-antd';
import {Location} from '@angular/common';

@Component({
    selector: 'app-add',
    templateUrl: './add.component.html',
})
export class AddComponent implements OnInit {

    jpush: Jpush = {};

    jpushFrom: FormGroup;

    constructor(
        private jpushService: JpushService,
        private fb: FormBuilder,
        private msgService: NzMessageService,
        private location: Location,
    ) {
    }

    ngOnInit() {
        this.jpushFrom = this.fb.group({
            title: ['', Validators.required],
            content: ['', Validators.required],
        });
    }

    save() {

        const val = this.jpushFrom.value;
        this.jpush.content = val['content'];
        this.jpush.title = val['title'];

        this.jpushService.addjpush(this.jpush).subscribe(res => {
            this.msgService.success('发送成功');
            this.location.back();
        }, __ => {

        });
    }

}
